local shibei = fk.CreateSkill {
  name = "lvshi__shibei",
  tags = {"ready_skill"},
}

Fk:loadTranslationTable{
  ["lvshi__shibei"] = "矢北",
  [":lvshi__shibei"] = "<a href='diy_ready_skill'>蓄势技</a>，你可将一张牌当【闪】或【无懈可击】使用；当你不以此法使用【闪】或【无懈可击】或受到伤害后，你重置此技能。",

  ["$lvshi__shibei1"] = "唯寄归心，随雁北还。",
  ["$lvshi__shibei2"] = "我如逆磁，矢志司北。",
}

local DIY = require "packages/diy_utility/diy_utility"
shibei:addEffect("viewas", {
  pattern = "jink,nullification",
  card_filter = Util.TrueFunc,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return nil end
    local card = Fk:cloneCard("lvshi__jink")
    if Fk.currentResponsePattern == "nullification" then
      card = Fk:cloneCard("lvshi__nullification")
    end
    card.skillName = shibei.name
    card:addSubcards(cards)
    return card
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function(self, player, response)
    if response then return false end
    return not DIY.isReadying(player, shibei.name)
  end,
})

shibei:addEffect(fk.AfterCardUseDeclared, {
  can_refresh = function(self, event, target, player, data)
    if target == player and player:hasSkill(shibei.name, true) and DIY.isReadying(player, "lvshi__shibei") then
      return (data.card.trueName == "jink" or data.card.trueName == "nullification") and data.card.skillName ~= "lvshi__shibei"
    end
  end,
  on_refresh = function(self, event, target, player, data)
    --player.room:removeTableMark(player, "@diy_skill_readying", "lvshi__shibei")
    DIY.resetReadySkill(player, shibei.name, shibei.name, true)
  end,
})

shibei:addEffect(fk.Damaged, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(shibei.name, true) and DIY.isReadying(player, "lvshi__shibei")
  end,
  on_refresh = function(self, event, target, player, data)
    DIY.resetReadySkill(player, shibei.name, shibei.name, true)
  end,
})

return shibei
